package cn.codingtalk.tacomallcommon.util;

import com.alibaba.fastjson.JSONObject;

public class RequestUtil extends JSONObject {

    public int getInt(String key) throws Exception {
        int value = super.getIntValue(key);
        if (value == 0) {
            ExceptionUtil.throwBizException("param key can not be blank: " + key);
        }
        return value;
    }

    public int getInt(String key, int defaultValue) throws Exception {
        int value = super.getIntValue(key) != 0 ? super.getIntValue(key) : defaultValue;
        if (StringUtil.isBlank(value + "")) {
            ExceptionUtil.throwBizException("param key and default can not be both blank: " + key);
        }
        return value;
    }

    public String getStr(String key) throws Exception {
        String value = super.getString(key);
        if (StringUtil.isBlank(value)) {
            ExceptionUtil.throwBizException("param key can not be blank: " + key);
        }
        return value;
    }
}

